# Makefile for Autoconf.
# -*-Makefile-*-
# @configure_input@

srcdir      = @srcdir@
VPATH       = @srcdir@

prefix      = @prefix@
exec_prefix = @exec_prefix@
bindir      = @bindir@
datadir     = @datadir@
exec_name   = xshisen
class_name  = XShisen

XSHISENLIB = $(datadir)/$(exec_name)
CXXFLAGS = @CXXFLAGS@
CPPFLAGS = @CPPFLAGS@
LDFLAGS  = @LDFLAGS@
DEFS     = @DEFS@
CXX      = @CXX@
INSTALL  = @INSTALL@
INSTALLP = @INSTALL_PROGRAM@
INSTALLD = @INSTALL_DATA@
MKDIR    = @MKDIR@
JAPANESE = @JAPANESE@
XAD_DIR  = @XAD_DIR@
JXAD_DIR = @JXAD_DIR@
MANDIR   = @mandir@

SRCS = main.C menubar.C body.C mahjong.C timer.C score.C \
       history.C image.C actions.C callbacks.C readxpm.C \
       common.C gamesize.C kconv.C nonstandard.C
OBJS = main.o menubar.o body.o mahjong.o timer.o score.o \
       history.o image.o actions.o callbacks.o readxpm.o \
       common.o gamesize.o kconv.o nonstandard.o
PROGS = $(exec_name)
AD    = XShisen.ad
ADJ   = XShisen-j.ad
SCF   = xshisen-scores

LIBS      = @LIBS@ 
CODECONV  = ./$(exec_name) -KCONV jis

all: $(PROGS)

$(exec_name): $(OBJS)
	$(CXX) $(LDFLAGS) $(OBJS) $(LIBS) -o $(exec_name)

install: $(PROGS) $(AD) $(ADJ)
	@echo "XShisen executable directory is " $(bindir)
	@$(MKDIR) $(bindir)
	@chmod 755 $(bindir)
	$(INSTALLP) $(PROGS) $(bindir)/$(PROGS)
	@echo "XShisen data directory is " $(XSHISENLIB)
	@$(MKDIR) $(XSHISENLIB)
	@chmod 755 $(XSHISENLIB)
	@if [ -f $(XSHISENLIB)/$(SCF) ]; then \
	echo "Old high-score file exists."; \
	else\
	$(INSTALL) -m 0666 $(SCF) $(XSHISENLIB)/$(SCF); \
	fi
	@set -x; \
	for file in pixmaps/*.xpm; do \
		$(INSTALLD) $$file $(XSHISENLIB)/`basename $$file`; \
	done
	$(INSTALLD) $(AD) $(XAD_DIR)/$(class_name)
	$(INSTALLD) $(ADJ) $(JXAD_DIR)/$(class_name)

install.man: $(exec_name).jman $(exec_name).man
	$(INSTALLD) $(exec_name).man $(MANDIR)/man6/$(exec_name).6
	$(INSTALLD) $(exec_name).jman $(MANDIR)/$(JAPANESE)/man6/$(exec_name).6

clean:
	rm -f *.o $(PROGS) $(AD) $(ADJ) $(exec_name).jman
distclean: clean
	rm -f config.log config.cache config.status config.h Makefile

$(exec_name).jman: $(exec_name) xshisen.jman-jis
	$(CODECONV) < xshisen.jman-jis > $(exec_name).jman

$(ADJ): $(exec_name) XShisen-j.ad.ad
	$(CODECONV) < XShisen-j.ad.ad > XShisen-j.ad

$(AD): $(exec_name) XShisen.ad.ad
	$(CODECONV) < XShisen.ad.ad > XShisen.ad

.SUFFIXES: .C
.C.o:
	$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $(DEFS) $< -o $@
